package model;

import java.util.HashMap;
import java.util.LinkedList;

/**
 * Class for keeping all the paths in the graph for a given node with a index for nondeterministic graph 
 * @author DarkoLaptop2
 *
 */
/**
 * @author DarkoLaptop2
 *
 */
public class NodePathsHashTable {

	private HashMap<Integer, LinkedList<String>> table;

	/**
	 * Constructor of the class. Creates a new hash table
	 * 
	 */
	public NodePathsHashTable() {
		table = new HashMap<Integer, LinkedList<String>>();
	}

	
	/** Method for inserting node path for a given node
	 * @param nodeIndex - the index of the node
	 * @param path - the path starting for the node
	 */
	public void insertNodePath(int nodeIndex, String path) {
		LinkedList<String> pathsList=table.get(nodeIndex);
		if (pathsList==null)
			pathsList=new LinkedList<String>();
		pathsList.addLast(path);
		table.put(nodeIndex, pathsList);
	}

	/** Remove all paths for a given node 
	 * @param nodeIndex - the index of the node
	 */
	public void removeNodePath(int nodeIndex) {
		table.remove(nodeIndex);
	}
	
	/** Method for getting all the node paths for a given node index
	 * @param nodeIndex - the index of the node
	 * @return list of all paths starting from the given node
	 */
	public LinkedList<String> getNodePaths(int nodeIndex) {
		LinkedList<String> allPaths = new LinkedList<String>();
		LinkedList<String> paths=table.get(nodeIndex);
		if(paths!=null)
			for(String restriction:paths)
				allPaths.add(restriction);
		return allPaths;
	}

	
	/** 
	 * Method for printing the table entries
	 * @return String - resulting table for printing
	 */
	public String toString()
	{
		String s="";
		for(Integer index:table.keySet())
			s+="Transition: "+index+" value: "+getNodePaths(index).toString()+" \n";
		return s;
	}
}

